package indi.caibo.service_edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import indi.caibo.commonutils.R;
import indi.caibo.service_edu.entity.EduCourse;
import indi.caibo.service_edu.entity.EduTeacher;
import indi.caibo.service_edu.service.EduCourseService;
import indi.caibo.service_edu.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Bo Cai
 * @version 1.0
 * @date 2021/11/20 21:32
 */
@Api(tags = "首页模块")
@RestController
@RequestMapping("/edu-service")
public class EduIndexController {
    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index() {
        //查询前8条热门课程
        List<EduCourse> courseList = courseService.selectHot8Courses();
        //查询前4条名师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
